from django.db import models
from django.contrib.auth.models import AbstractUser,Group


# Create your models here.


class UserProfile(AbstractUser):
    """
    用户信息
    """
    IS_VIP = (
        (False, '非会员'),
        (True, '会员')
    )

    GENDER = (
        ("1", "男"),
        ("2", "女")
    )

    nick_name = models.CharField(default="", max_length=50, verbose_name="昵称", null=True, blank=True)
    birthday = models.DateTimeField(verbose_name="生日", null=True, blank=True, auto_created=True)
    gender = models.CharField(max_length=1, choices=GENDER, default="1", null=True,
                              blank=True)
    address = models.CharField(max_length=100, default="", verbose_name='用户所在城市', null=True, blank=True)
    mobile = models.CharField(max_length=14, default="", verbose_name='手机号')
    register_time = models.DateTimeField(auto_now=True)

    class Meta:
        verbose_name = "用户信息"
        verbose_name_plural = verbose_name

    def __str__(self):
        return str(self.username)


class CaptchaKind(models.Model):
    """
    验证码类型,比如登录验证码,找回密码验证码等等
    """

    name = models.CharField(max_length=6, verbose_name='验证码类型', help_text='验证码类型')
    expire_time = models.PositiveIntegerField(verbose_name='验证码有效时间 单位分钟',help_text='验证码有效时间 单位分钟',default=5)
    add_time = models.DateTimeField(auto_now=True, verbose_name='添加时间', help_text='添加时间')

    class Meta:
        verbose_name = '验证码类型'
        verbose_name_plural = verbose_name


class Captcha(models.Model):
    """
    用户验证码,登录 找回
    """

    captcha = models.CharField(max_length=6, verbose_name='验证码', help_text='验证码')
    user = models.ForeignKey(UserProfile, verbose_name='用户', help_text='用户')
    add_time = models.DateTimeField(auto_now=True, verbose_name='添加时间', help_text='添加时间')
    kind = models.ForeignKey(CaptchaKind, verbose_name='验证码类型', help_text='验证码类型')

    class Meta:
        verbose_name = '用户的验证码'
        verbose_name_plural = '用户的验证码'



class CaptchaReg(models.Model):
    """
    用户注册验证码
    """

    captcha = models.CharField(max_length=6, verbose_name='验证码', help_text='验证码')
    email = models.EmailField(verbose_name='注册邮箱',help_text='注册邮箱')
    add_time = models.DateTimeField(auto_now=True, verbose_name='添加时间', help_text='添加时间')

    class Meta:
        verbose_name = '用户注册验证码'
        verbose_name_plural = '用户注册验证码'
